* Change to directory where data files are located *
* Figure 1 *
use "Iraq_data_110th_combined.dta", clear
twoway (kdensity fp_mean if democrat == 1, lcolor(black)) (kdensity fp_mean if democrat == 0, lcolor(gs5) lpattern(dash)), graphregion(color(white)) xti("Hawkish Ideology") yti("Density") legend(order(1 "Democrats" 2 "Republicans"))
* Figure 2 *
use "Iraq_data_110th_combined.dta", clear
nbreg antiwar opposition_party leader anyfrcommittee  seniority veteran female latino black  senate
margins, at(opposition_party=(0(1)1) veteran=(0) female=(0) latino=(0) black=(0) leader=(0) anyfrcommittee=(0)senate=0) vsquish atmeans
marginsplot, x(opposition_party) plotopts(mcolor(black) lcolor(black))  ytitle(Predicted # speeches) ti("Iraq: Anti-War") graphregion(fcolor(white)) saving("iraqantiparty.gph", replace) 
nbreg prowar opposition_party leader anyfrcommittee  seniority veteran female latino black  senate
margins, at(opposition_party=(0(1)1) veteran=(0) female=(0) latino=(0) black=(0) leader=(0) anyfrcommittee=(0)senate=0) vsquish atmeans
marginsplot, x(opposition_party) plotopts(mcolor(black) lcolor(black))  ytitle(Predicted # speeches) ti("Iraq: Pro-War") graphregion(fcolor(white)) ylabel(0 5 10 15) saving("iraqproparty.gph", replace)

use "Afghanistan_data_111th_combined.dta", clear
nbreg anti_war_new opposition_party leader anyfrcommittee seniority veteran female latino black  senate
margins, at(opposition_party=(0(1)1) veteran=(0) female=(0) latino=(0) black=(0) leader=(0) anyfrcommittee=(0) senate=0) vsquish atmeans
marginsplot, x(opposition_party) plotopts(mcolor(black) lcolor(black))   ytitle(Predicted # speeches) ti("Afghanistan: Anti-War") graphregion(fcolor(white)) ylabel(0 1 2 3) saving("afghanantiparty.gph", replace)
nbreg pro_war_new opposition_party leader anyfrcommittee seniority veteran female latino black  senate
margins, at(opposition_party=(0(1)1) veteran=(0) female=(0) latino=(0) black=(0) leader=(0) anyfrcommittee=(0) senate=0) vsquish atmeans
marginsplot, x(opposition_party) plotopts(mcolor(black) lcolor(black))   ytitle(Predicted # speeches) ti("Afghanistan: Pro-War") graphregion(fcolor(white)) ylabel(0 1 2 3) saving("afghanproparty.gph", replace)

graph combine "iraqantiparty.gph" "iraqproparty.gph" "afghanantiparty.gph" "afghanproparty.gph", graphregion(color(white))

* Figure 3 *
use "Iraq_data_110th_combined.dta", clear
nbreg antiwar fp_mean leader anyfrcommittee seniority veteran female latino black  senate if democrat == 1
margins, at(fp_mean=(-4.5(.5).5)  veteran=(0) female=(0) latino=(0) black=(0) leader=(0) anyfrcommittee=(0) senate=(0)) vsquish atmeans
marginsplot, x(fp_mean)  recast(line) 
marginsplot, recast(line) recastci(rarea) ti(Democrats) graphregion(color(white)) ytitle(Predicted # speeches) ti("Democrats: Anti-War") saving("demiraqantiideo.gph", replace) plotopts(lcolor(black)) ciopts(color(gs10))

nbreg prowar fp_mean leader anyfrcommittee seniority veteran female latino black senate if democrat == 1
margins, at(fp_mean=(-4.5(.5).5)  veteran=(0) female=(0) latino=(0) black=(0) leader=(0) anyfrcommittee=(0) senate=(0)) vsquish atmeans
marginsplot, x(fp_mean)  recast(line) 
marginsplot, recast(line) recastci(rarea) ti(Democrats) graphregion(color(white)) ytitle(Predicted # speeches) ylabel(0 1 2) ti("Democrats: Pro-War") saving("demiraqproideo.gph", replace) plotopts(lcolor(black)) ciopts(color(gs10))

nbreg antiwar fp_mean leader anyfrcommittee seniority veteran female latino black senate if republican == 1
margins, at(fp_mean=(0(.5)4.5)  veteran=(0) female=(0) latino=(0) black=(0) leader=(0) anyfrcommittee=(0) senate=(0)) vsquish atmeans
marginsplot, x(fp_mean)  recast(line) 
marginsplot, recast(line) recastci(rarea) ti(Democrats) graphregion(color(white)) ytitle(Predicted # speeches) ti("Republicans: Anti-War") saving("gopiraqantiideo.gph", replace) plotopts(lcolor(black)) ciopts(color(gs10))

nbreg prowar fp_mean leader anyfrcommittee seniority veteran female latino black senate if republican == 1
margins, at(fp_mean=(0(.5)4.5)  veteran=(0) female=(0) latino=(0) black=(0) leader=(0) anyfrcommittee=(0) senate=(0)) vsquish atmeans
marginsplot, x(fp_mean)  recast(line) 
marginsplot, recast(line) recastci(rarea) ti(Democrats) graphregion(color(white)) ytitle(Predicted # speeches) ti("Republicans: Pro-War") saving("gopiraqproideo.gph", replace) plotopts(lcolor(black)) ciopts(color(gs10))

graph combine "demiraqantiideo.gph" "demiraqproideo.gph" "gopiraqantiideo.gph" "gopiraqproideo.gph", graphregion(color(white))


* Figure 4 *
use "Afghanistan_data_111th_combined.dta", clear
nbreg anti_war_new fp_mean leader anyfrcommittee seniority veteran female latino black senate  if democrat == 1
margins, at(fp_mean=(-5(.5)0)  veteran=(0) female=(0) latino=(0) black=(0) leader=(0) anyfrcommittee=(0) senate=(0)) vsquish atmeans
marginsplot, x(fp_mean)  recast(line) 
marginsplot, recast(line) recastci(rarea) ti("Democrats: Anti-War") graphregion(color(white)) ytitle(Predicted # speeches) saving("demafghanantiideo.gph", replace) plotopts(lcolor(black)) ciopts(color(gs10))

nbreg pro_war_new fp_mean leader anyfrcommittee seniority veteran female latino black senate if democrat == 1
margins, at(fp_mean=(-5(.5)0)  veteran=(0) female=(0) latino=(0) black=(0) leader=(0) anyfrcommittee=(0) senate=(0)) vsquish atmeans
marginsplot, x(fp_mean)  recast(line) 
marginsplot, recast(line) recastci(rarea) ti("Democrats: Pro-War") graphregion(color(white)) ytitle("Predicted # speeches") ylabel(.2 .4 .6 .8 1)  saving("demafghanproideo.gph", replace) plotopts(lcolor(black)) ciopts(color(gs10))

nbreg anti_war_new fp_mean leader anyfrcommittee seniority veteran female latino black senate if republican == 1
margins, at(fp_mean=(0(.5)4.5)  veteran=(0) female=(0) latino=(0) black=(0) leader=(0) anyfrcommittee=(0) senate=(0)) vsquish atmeans
marginsplot, x(fp_mean)  recast(line) 
marginsplot, recast(line) recastci(rarea) ti("Republicans: Anti-War") graphregion(color(white)) ytitle(Predicted # speeches) ylabel(0 .2 .4)  saving("gopafghanantiideo.gph", replace) plotopts(lcolor(black)) ciopts(color(gs10))

nbreg pro_war_new fp_mean leader anyfrcommittee seniority veteran female latino black senate if republican == 1
margins, at(fp_mean=(0(.5)4.5)  veteran=(0) female=(0) latino=(0) black=(0) leader=(0) anyfrcommittee=(0) senate=(0)) vsquish atmeans
marginsplot, x(fp_mean)  recast(line) 
marginsplot, recast(line) recastci(rarea) ti("Republicans: Pro-War") graphregion(color(white)) ytitle(Predicted # speeches) ylabel(.2 .4 .6 .8 1)  saving("gopafghanproideo.gph", replace) plotopts(lcolor(black)) ciopts(color(gs10))

graph combine "demafghanantiideo.gph" "demafghanproideo.gph" "gopafghanantiideo.gph" "gopafghanproideo.gph", graphregion(color(white))

* Figure 5 *
use "Iraq_data_110th_combined.dta", clear
nbreg antiwar  leader anyfrcommittee seniority veteran female latino black  i.opposition_party##i.underwater
margins, at(opposition_party=(0(1)1) underwater=(0(1)1)  veteran=(0) female=(0) latino=(0) black=(0) leader=(0) anyfrcommittee=(0)) vsquish atmeans
mplotoffset, x(underwater)  ytitle(Predicted # speeches) graphregion(fcolor(white)) ti("Iraq: Anti-War") saving("iraq_anti_under.gph", replace)  plot1opts(mcolor(black) msymbol(square) lpattern(dash) lcolor(black)) plot2opts(lcolor(black) mcolor(black)) ciopts(lcolor(black)) legend(order(3 "Co-partisan" 4 "Opposition")) xti("Constituency partisanship opposite member") scale(.85)

nbreg prowar  leader anyfrcommittee seniority veteran female latino black  i.opposition_party##i.underwater
margins, at(opposition_party=(0(1)1) underwater=(0(1)1)  veteran=(0) female=(0) latino=(0) black=(0) leader=(0) anyfrcommittee=(0)) vsquish atmeans
mplotoffset, x(underwater)  ytitle(Predicted # speeches) graphregion(fcolor(white)) ti("Iraq: Pro-War")  ylabel(0 2 4 6) saving("iraq_pro_under.gph", replace) plot1opts(mcolor(black) msymbol(square) lpattern(dash) lcolor(black)) legend(order(3 "Co-partisan" 4 "Opposition")) xti("Constituency partisanship opposite member") plot2opts(lcolor(black) mcolor(black)) ciopts(lcolor(black)) scale(.85)

use "Afghanistan_data_111th_combined.dta", clear
nbreg anti_war_new  leader anyfrcommittee seniority veteran female latino black  i.opposition_party##i.underwater
margins, at(opposition_party=(0(1)1) underwater=(0(1)1)  veteran=(0) female=(0) latino=(0) black=(0) leader=(0) anyfrcommittee=(0)) vsquish atmeans 
mplotoffset, x(underwater) ytitle(Predicted # speeches) graphregion(fcolor(white)) ti("Afghanistan: Anti-War") ylabel(0 1 2) saving("afghan_anti_under.gph", replace)  plot1opts(mcolor(black) msymbol(square) lpattern(dash) lcolor(black)) legend(order(3 "Co-partisan" 4 "Opposition")) xti("Constituency partisanship opposite member") plot2opts(lcolor(black) mcolor(black)) ciopts(lcolor(black)) scale(.85)

nbreg pro_war_new  leader anyfrcommittee seniority veteran female latino black  i.opposition_party##i.underwater
margins, at(opposition_party=(0(1)1) underwater=(0(1)1)  veteran=(0) female=(0) latino=(0) black=(0) leader=(0) anyfrcommittee=(0)) vsquish atmeans
mplotoffset, x(underwater)   ytitle(Predicted # speeches) graphregion(fcolor(white)) ti("Afghanistan: Pro-War")  ylabel(0 1 2) saving("afghan_pro_under.gph", replace) plot1opts(mcolor(black) msymbol(square) lpattern(dash) lcolor(black)) legend(order(3 "Co-partisan" 4 "Opposition")) xti("Constituency partisanship opposite member") plot2opts(lcolor(black) mcolor(black)) ciopts(lcolor(black)) scale(.85)

grc1leg2 "iraq_anti_under.gph" "iraq_pro_under.gph" "afghan_anti_under.gph" "afghan_pro_under.gph", graphregion(color(white))

* Table 1 -- Baseline party models *
use "Iraq_data_110th_combined.dta", clear
nbreg antiwar opposition_party leader anyfrcommittee  seniority veteran female latino black  senate
outreg2 using table1, word dec(2) label replace
nbreg prowar opposition_party leader anyfrcommittee  seniority veteran female latino black  senate
outreg2 using table1, word dec(2) label append
use "Afghanistan_data_111th_combined.dta", clear
nbreg anti_war_new opposition_party leader anyfrcommittee   seniority veteran female latino black  senate
outreg2 using table1, word dec(2) label append
nbreg pro_war_new opposition_party leader anyfrcommittee   seniority veteran female latino black  senate 
outreg2 using table1, word dec(2) label append

* Table 2 -- Effect of Ideology on Partisans' Rhetoric *
use "Iraq_data_110th_combined.dta", clear
nbreg antiwar fp_mean leader anyfrcommittee  seniority veteran female latino black  senate if democrat == 1
outreg2 using table2, word dec(2) label replace
nbreg prowar fp_mean leader anyfrcommittee  seniority veteran female latino black  senate if democrat == 1
outreg2 using table2, word dec(2) label append
nbreg antiwar fp_mean leader anyfrcommittee  seniority veteran female latino black  senate  if republican == 1
outreg2 using table2, word dec(2) label append
nbreg prowar fp_mean leader anyfrcommittee  seniority veteran female latino black  senate  if republican == 1
outreg2 using table2, word dec(2) label append
use "Afghanistan_data_111th_combined.dta", clear
nbreg anti_war_new fp_mean leader anyfrcommittee seniority veteran female latino black senate  if democrat == 1
outreg2 using table2, word dec(2) label append
nbreg pro_war_new fp_mean leader anyfrcommittee seniority veteran female latino black senate if democrat == 1
outreg2 using table2, word dec(2) label append
nbreg anti_war_new fp_mean leader anyfrcommittee seniority veteran female latino black senate if republican == 1
outreg2 using table2, word dec(2) label append
nbreg pro_war_new fp_mean leader anyfrcommittee seniority veteran female latino black senate if republican == 1
outreg2 using table2, word dec(2) label append

* Table 3 -- District Partisanship Moderates the Influence of Member Partisanship on Rhetoric *
use "Iraq_data_110th_combined.dta", clear
nbreg antiwar  leader anyfrcommittee seniority veteran female latino black  i.opposition_party##i.underwater
outreg2 using underwater, word dec(2) label replace
nbreg prowar  leader anyfrcommittee seniority veteran female latino black  i.opposition_party##i.underwater
outreg2 using underwater, word dec(2) label append
use "Afghanistan_data_111th_combined.dta", clear
nbreg anti_war_new  leader anyfrcommittee seniority veteran female latino black  i.opposition_party##i.underwater
outreg2 using underwater, word dec(2) label append
nbreg pro_war_new  leader anyfrcommittee seniority veteran female latino black  i.opposition_party##i.underwater
outreg2 using underwater, word dec(2) label append

* Table 4 -- Summary Statistics *
use "Afghanistan_data_111th_combined.dta", clear
* To get total numbers of speeches, multiply mean by number of observations in each case *
sum  anti_war_pro_admin if democrat == 1
sum  anti_war_pro_admin if democrat == 1 & underwater == 1

* Table 5 *
ttest anti_war_pro_admin if underwater == 0, by(democrat)
ttest anti_war_pro_admin if underwater == 1, by(democrat)
ttest pro_war_anti_admin if underwater == 0, by(democrat)
ttest pro_war_anti_admin if underwater == 1, by(democrat)
